package cn.iocoder.yudao.module.bpm.service.feign;

import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.module.bpm.feign.bpm.AdminUserApi;
import com.xueyi.common.core.constant.basic.SecurityConstants;
import com.xueyi.common.core.domain.R;
import com.xueyi.common.core.utils.ServletUtils;
import com.xueyi.common.core.utils.collection.CollectionUtils;
import com.xueyi.system.api.organize.domain.dto.SysUserDto;
import com.xueyi.system.api.organize.feign.RemoteUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * Admin 用户 API 实现类
 *
 * @author 芋道源码
 */
@Service
public class AdminUserApiImpl implements AdminUserApi {

    @Resource
    private RemoteUserService userService;

    @Override
    public SysUserDto getUser(Long id) {
        Long enterpriseId = Long.parseLong(ServletUtils.getRequest().getHeader(SecurityConstants.ENTERPRISE_ID));
        String sourceName = ServletUtils.getRequest().getHeader(SecurityConstants.SOURCE_NAME);
        R<SysUserDto> userResult = userService.getUserByID(id,enterpriseId,sourceName,SecurityConstants.INNER);
        SysUserDto user = userResult.getResult();
        return user;
    }

    @Override
    public List<SysUserDto> getUsersByDeptIds(Collection<Long> deptIds) {
        /*List<AdminUserDO> users = userService.getUsersByDeptIds(deptIds);
        return UserConvert.INSTANCE.convertList4(users);*/
        return null;
    }

    @Override
    public List<SysUserDto> getUsersByPostIds(Collection<Long> postIds) {
        /*List<AdminUserDO> users = userService.getUsersByPostIds(postIds);
        return UserConvert.INSTANCE.convertList4(users);*/
        return null;
    }

    @Override
    public Map<Long, SysUserDto> getUserMap(Collection<Long> userIds) {
        if (CollUtil.isEmpty(userIds)) {
            return new HashMap<>();
        }
        SysUserDto sysUserDto = new SysUserDto();
        sysUserDto.setUserIds(userIds);
        Long enterpriseId = Long.parseLong(ServletUtils.getRequest().getHeader(SecurityConstants.ENTERPRISE_ID));
        String sourceName = ServletUtils.getRequest().getHeader(SecurityConstants.SOURCE_NAME);
        R<List<SysUserDto>> userResult = userService.getUsers(sysUserDto,enterpriseId,sourceName,SecurityConstants.INNER);
        List<SysUserDto> users = userResult.getResult();
        return CollectionUtils.convertMap(users, SysUserDto::getId);
    }

    @Override
    public void validUsers(Set<Long> ids) {
        //userService.validUsers(ids);
    }

}
